import java.io.BufferedInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.URL;


public class CharCount {
	public static void main (String[] args) throws IOException{
		int[] abc = new int[26];
		int[] aBC = new int[26];
		String out;
		int max=0;
		boolean end = true;
		int i=0;
		char j=0;
		URL url;
		BufferedInputStream in;
		PrintWriter ou = new PrintWriter(new FileWriter("Ergebnis.txt"));
		if (args.length < 1)
			System.out.println("Please Insert URL to File");
		else{
			url = new URL( args[0] );
			in = new BufferedInputStream(url.openStream());
			while (in.available() > 0){				// Count the Letters 
				i = in.read();						
				j = (char) i;
				System.out.print(j);
				if (Character.isUpperCase(j))
					aBC[i-65]++;				
				if (Character.isLowerCase(j))
					abc[i-97]++; 
			}
			in.close();
			System.out.println();
		while (end){								// Print the small Letters
			for (int k =0 ;k<26; k++)
				if  (abc[k] == 0)
					end = false;
				else{
					max = (abc[max] < abc[k]) ? k : max;
				}
				end = (abc[max] != 0) ? true : false;
			if (end){
				out =("Der Buchstabe  "+ (char)(max+97) + "  taucht  " + abc[max] + "  mal auf.");
				abc[max] = 0;
				max = 0;
				ou.write(out);
				ou.write(System.getProperty("line.separator"));	
				System.out.println(out);
			}
		}
		end = true;
		while (end){								// Print the capital Letters
			for (int k =0 ;k<26; k++)	
				if  (aBC[k] == 0)
					end = false;
				else{
					max = (aBC[max] < aBC[k]) ? k : max;
				}
				end = (aBC[max] != 0) ? true : false;
			if (end){
				out =("Der Buchstabe  "+ (char)(max+65) + "  taucht  " + aBC[max] + "  mal auf.");
				aBC[max] = 0;
				max = 0;
				ou.write(out);
				ou.write(System.getProperty("line.separator"));	
				System.out.println(out);
			}
		}
		ou.close();
	}
	}
}
